<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>基础知识</title>
	<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"" rel="stylesheet">
	<link href="https://cdn.bootcdn.net/ajax/libs/animate.css/3.2.3/animate.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../static/css/public.css" />
	<style type="text/css">
		li{
			text-indent: 2em;
			list-style: none;
		}
	</style>
</head>
<body>
	<!-- 回到顶部 -->
	<div class="topBtn">
		<a href="#top">
			<i class="fa fa-long-arrow-up"></i>
		</a>
	</div>
	<!--右边内容-->
	<div id="app" class="main animated fadeInRight">
		<div class="shadow" v-cloak>
			<div class="Table" v-cloak id="top">
				<div class="TableRow" v-for="(el,index) in list">
					<a class="RowLeft" 
					:title="el.name"
					:href="'#'+el.id">{{el.name}}</a>
					<span class="RowRight">{{el.explain}}</span>
				</div>
			</div>	
			<div>
				<h4 id="compare">比较俩个数是否值相等</h4>
				<p>两个数值的比较使用场景是在可编辑组件中关闭或离开页面时判断是否修改</p>
				<pre>
	function deepCompare(x, y) {
		var i, l, leftChain, rightChain;
	
		function compare2Objects(x, y) {
			var p;
	
			// remember that NaN === NaN returns false
			// and isNaN(undefined) returns true
			if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') {
				return true;
			}
	
			// Compare primitives and functions.     
			// Check if both arguments link to the same object.
			// Especially useful on the step where we compare prototypes
			if (x === y) {
				return true;
			}
	
			// Works in case when functions are created in constructor.
			// Comparing dates is a common scenario. Another built-ins?
			// We can even handle functions passed across iframes
			if ((typeof x === 'function' && typeof y === 'function') ||
				(x instanceof Date && y instanceof Date) ||
				(x instanceof RegExp && y instanceof RegExp) ||
				(x instanceof String && y instanceof String) ||
				(x instanceof Number && y instanceof Number)) {
				return x.toString() === y.toString();
			}
	
			// At last checking prototypes as good as we can
			if (!(x instanceof Object && y instanceof Object)) {
				return false;
			}
	
			if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) {
				return false;
			}
	
			if (x.constructor !== y.constructor) {
				return false;
			}
	
			if (x.prototype !== y.prototype) {
				return false;
			}
	
			// Check for infinitive linking loops
			if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {
				return false;
			}
	
			// Quick checking of one object being a subset of another.
			// todo: cache the structure of arguments[0] for performance
			for (p in y) {
				if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
					return false;
				} else if (typeof y[p] !== typeof x[p]) {
					return false;
				}
			}
	
			for (p in x) {
				if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
					return false;
				} else if (typeof y[p] !== typeof x[p]) {
					return false;
				}
				switch (typeof(x[p])) {
					case 'object':
					case 'function':
						leftChain.push(x);
						rightChain.push(y);
						if (!compare2Objects(x[p], y[p])) {
							return false;
						}
						leftChain.pop();
						rightChain.pop();
						break;
					default:
						if (x[p] !== y[p]) {
							return false;
						}
						break;
				}
			}
			return true;
		}
	
		if (arguments.length &lt; 1) {
			return true; 
			//Die silently? Don't know how to handle such case, please help...
			// throw "Need two or more arguments to compare";
		}
	
		for (i = 1, l = arguments.length; i &lt; l; i++) {
			leftChain = []; //Todo: this can be cached
			rightChain = [];
			if (!compare2Objects(arguments[0], arguments[i])) {
				return false;
			}
		}
		return true;
	}
				</pre>
			</div>
		</div>
	</div>
	<!--页面加载进度条-->
	<script src="https://cdn.bootcdn.net/ajax/libs/pace/0.5.0/pace.min.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.5.17/vue.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var app = new Vue({
			el: "#app",
			data: function () {
				return {
					list:[
						{name:"比较俩个数是否值相等",id:"compare",explain:'主要比较值是否相等，不比较是否引用同个对象'},
					]
				}
			},
		})
	</script>
</body>

</html>